import { createRouter, createWebHistory } from 'vue-router';
import api from '../api';



let routesConfig = []
// 在setup()方法内部定义一个异步函数
async function getRoutes() {
    var res = await api.post("RouteConfig/GetAllData")
    res.Data.map(x =>
        routesConfig.push({
            path: x.Path,
            label: x.Label,
            ...x,
            component: () => import(x.Component)
        })
    )
    localStorage.setItem('routesConfig', JSON.stringify(routesConfig))
}

//从api读取配置
await getRoutes();

const router = createRouter({
    history: createWebHistory(),
    routes: routesConfig,
});


// router.addRoute(
//     {
//         path: '/a',
//         label: 'test',
//         component: () => import('../views/Home.vue')
//     }
// );

export default router;